package com.itstudy.service.impl;

import com.itstudy.mapper.CategoryMapper;
import com.itstudy.pojo.Category;
import com.itstudy.service.CategoryService;
import com.itstudy.utils.ThreadLocalUtil;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public void add(Category category) {
        Map<String,Object> map= ThreadLocalUtil.get();
        category.setCreateUser((Integer) map.get("id"));
        categoryMapper.insert(category);
    }

    @Override
    public List<Category> query() {
        return categoryMapper.query();
    }

    @Override
    public Category findById(Integer id) {
        return categoryMapper.findById(id);
    }

    @Override
    public void update(Category category) {
        categoryMapper.update(category);
    }

    @Override
    public int deleteById(Integer id) {
       return categoryMapper.deleteById(id);
    }
}
